import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


/**
 *
 * @author Jacob Hohisel
 * 
 * co-author Brian
 *
 */

@SuppressWarnings("serial")
public class DraftFrame extends JFrame{
	
	private static final int WIDTH = 320;
	private static final int HEIGHT = 160;
	
	public static JFrame thisWindow;
	
	private static String analyst = "";
	private static String draft = "";
	
	private static JPanel framePanel;
	private static JPanel namePanel;
	private static JPanel draftPanel;
	private static JLabel nameLabel;
	private static JLabel draftLabel;
	private static JButton saveButton;
	private static JTextField nameField;
	private static JTextField draftField;
	
	private static String myName;
	
	public DraftFrame(String theName) {
		myName = theName;
		thisWindow = new JFrame("Add Draft to List");
		thisWindow.setSize(WIDTH, HEIGHT);
		thisWindow.setLocationRelativeTo(null);
		createPanels();
		thisWindow.add(framePanel);
	}
	private static void createPanels() {
		framePanel = new JPanel();
		namePanel = new JPanel();
		draftPanel = new JPanel();
		nameLabel = new JLabel("Analyst: ");
		draftLabel = new JLabel("Draft:     ");
		nameField = new JTextField();
		draftField = new JTextField();
		saveButton = new JButton("Save");
		
		saveButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				save();
			}
		});
		
		nameField.setPreferredSize(new Dimension(150, 20));
		draftField.setText(myName);
		draftField.setPreferredSize(new Dimension(150, 20));
		framePanel.setLayout(new BoxLayout(framePanel, BoxLayout.Y_AXIS));
		namePanel.setLayout(new FlowLayout());
		draftPanel.setLayout(new FlowLayout());
		namePanel.add(nameLabel);
		namePanel.add(nameField);
		draftPanel.add(draftLabel);
		draftPanel.add(draftField);
		framePanel.add(namePanel);
		framePanel.add(draftPanel);
		framePanel.add(saveButton);
	}
	
	public static void save() {
		// Send data off to the Analyst class
		
		analyst = nameField.getText();
		draft = draftField.getText();
		
		//author  Brian
		//Draft myDraft = new Draft(analyst,draft);
		//Analyst myAnalyst = new Analyst();
		//myAnalyst.addNewDraft(myDraft);

		//myAnalyst.saveDrafts();
		
		// Close window
		nameField.setText("");
		draftField.setText("");
		thisWindow.dispose();
	
	}
	
	public static String getAnalyst() {
		return analyst;
	}
	public static String getDraft() {
		return draft;
	}
 	
	public JFrame getFrame() {
		return thisWindow;
	}
	
}
